
#include <assert.h>

#include "spi/spi_master.h"
#include "hcpp/ptp2_log.h"
#include "hcpp/ptp2_master.h"
#include "hcpp/slave_list_transmitter.h"

#include "test/slave_table_test.h"

spi_master_t                spi_master;
slave_list_transmitter_t    slave_list_transmitter;
static ptp2_node_table_t    node_table;


int main(int argc, char* argv[])
{

  ptp2_log_init();
  PTP2_LOG_PRINTLN(PTP2_LOG_MASTER, PTP2_LOG_DEBUG, ("PTP2-Master init"));

  if (!ptp2_master_init()) {
      PTP2_LOG_PRINTLN(PTP2_LOG_MASTER, PTP2_LOG_ERROR, ("PTP2-Master init failed!"));
      return 1;
  }

  if(!spi_master_init(&spi_master)){
      return false;
  }


  /*
   * Test routines: fill up a slave table with dummy entries
   */
  test_fill_slave_table(1, &node_table);
  // check slave_table size
  assert(1==node_table.size);

  // crma added
  if(!slave_list_transmitter_init(&slave_list_transmitter, &node_table, &spi_master)){
    return false;
  }

  // trigger the slave list transmission as when a spi command has bee received
  slave_list_transmitter_start(&slave_list_transmitter);


  ptp2_master_mainloop();

  return 0;
}
